package com.szy.controller;

import com.szy.repo.UserRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.inject.Inject;
import javax.servlet.http.HttpServletRequest;

/**
 * Created by As on 2015/8/20.
 */
@Controller
@RequestMapping("/login")
public class LoginController {

    private static final Logger log = LoggerFactory.getLogger(LoginController.class);

    @Inject
    private UserRepository userRepository;

    @RequestMapping(method = RequestMethod.GET)
    public String login() {
        log.debug("显示用户登录界面");
        return "login";
    }

    @RequestMapping(method = RequestMethod.POST)
    public String login(String username, String password, Model model){
        if (userRepository.checkUser(username, password)){
            return "index";
        } else {
            return "login";
        }
    }
}
